package com.ruoyi.business.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.ObjectUtils;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ClassInfo;
import com.ruoyi.business.service.IClassInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 * 
 * @author lcz
 * @date 2025-02-20
 */
@Api(tags = "班级相关接口")
@RestController
@RequestMapping("/business/classInfo")
public class ClassInfoController extends BaseController
{
    @Autowired
    private IClassInfoService classInfoService;

    /**
     * 查询班级列表
     */
    @ApiIgnore
//    @PreAuthorize("@ss.hasPermi('business:classInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassInfo classInfo)
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        Long roleId = sysUser.getRoles().get(0).getRoleId();
        if (roleId.toString().equals("110")){
            classInfo.setSchoolId(sysUser.getSchoolId());
        }
        if (roleId.toString().equals("120")){
            classInfo.setTeacherId(sysUser.getUserId());
        }

        startPage();
        List<ClassInfo> list = classInfoService.selectClassInfoList(classInfo);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @ApiIgnore
//    @PreAuthorize("@ss.hasPermi('business:classInfo:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassInfo classInfo)
    {
        List<ClassInfo> list = classInfoService.selectClassInfoList(classInfo);
        ExcelUtil<ClassInfo> util = new ExcelUtil<ClassInfo>(ClassInfo.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @ApiIgnore
//    @PreAuthorize("@ss.hasPermi('business:classInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(classInfoService.selectClassInfoById(id));
    }

    /**
     * 新增班级
     */
    @ApiIgnore
//    @PreAuthorize("@ss.hasPermi('business:classInfo:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassInfo classInfo)
    {
        return toAjax(classInfoService.insertClassInfo(classInfo));
    }

    /**
     * 修改班级
     */
    @ApiIgnore
//    @PreAuthorize("@ss.hasPermi('business:classInfo:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassInfo classInfo)
    {
        return toAjax(classInfoService.updateClassInfo(classInfo));
    }

    /**
     * 删除班级
     */
    @ApiIgnore
//    @PreAuthorize("@ss.hasPermi('business:classInfo:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classInfoService.deleteClassInfoByIds(ids));
    }

    /** 前端接口 ***************************************************************************************************/
    /** 前端接口 ***************************************************************************************************/
    /** 前端接口 ***************************************************************************************************/

    /**
     * 查询老师名下所有班级列表
     * 接口路径：/classInfo/front/list
     */
    @GetMapping("/front/listByTeacherId")
    @ApiOperation("查询老师名下所有班级列表")
    public TableDataInfo<ClassInfo> frontListByTeacherId()
    {
        ClassInfo classInfo = new ClassInfo();
        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
        classInfo.setTeacherId(userId);
        startPage();
        List<ClassInfo> list = classInfoService.selectClassInfoList(classInfo);
        return getDataTable(list);
    }
//
//    /**
//     * 获取班级详细信息
//     * 接口路径：/classInfo/front/info
//     */
//    @ApiOperation("前台获取班级详细信息")
//    @GetMapping(value = "/front/info")
//    public R<ClassInfo> frontInfo(@RequestParam("id") Long id)
//    {
//        return R.ok(classInfoService.selectClassInfoById(id));
//    }
//
//    /**
//     * 新增班级
//     * 接口路径：/classInfo/front/add
//     */
//    @ApiOperation("前台新增班级")
//    @PostMapping("/front/add")
//    public AjaxResult frontAdd(@RequestBody ClassInfo classInfo)
//    {
//        return toAjax(classInfoService.insertClassInfo(classInfo));
//    }
//
//    /**
//     * 修改班级
//     * 接口路径：/classInfo/front/edit
//     */
//    @ApiOperation("前台修改班级")
//    @PostMapping("/front/edit")
//    public AjaxResult frontEdit(@RequestBody ClassInfo classInfo)
//    {
//        return toAjax(classInfoService.updateClassInfo(classInfo));
//    }
//
//    /**
//     * 删除班级
//     * 接口路径：/classInfo/front/delete
//     */
//    @ApiOperation("前台删除班级")
//    @GetMapping("/front/delete")
//    public AjaxResult frontRemove(@RequestParam Long[] ids)
//    {
//        return toAjax(classInfoService.deleteClassInfoByIds(ids));
//    }
}
